package com.prs.crm.action.approval;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.approval.ProcessNode;
import com.prs.crm.domain.approval.ProcessType;
import com.prs.crm.service.approval.ProcessNodeService;

public class ProcessNodeAction extends BaseAction{
	private PaginationSupport pagination;
	private Integer [] ids;
	private ProcessNodeService processNodeService;
	private ProcessNode processNode;
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public ProcessNodeService getProcessNodeService() {
		return processNodeService;
	}
	public void setProcessNodeService(ProcessNodeService processNodeService) {
		this.processNodeService = processNodeService;
	}
	public ProcessNode getProcessNode() {
		return processNode;
	}
	public void setProcessNode(ProcessNode processNode) {
		this.processNode = processNode;
	}
	/////////////////////////////////////////////////////////////////////////
	@Action("listProcessNode")
	public String listProcessNode(){
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(ProcessNode.class);
		this.setPagination(this.processNodeService.listByPage(criteria, 
				this.getPaginationHelper().prepare(pagination)));
		return SUCCESS;
	}
	@Action(value="saveProcessNode",results={
			@Result(name="success",type="redirect",location="listProcessNode"),
			@Result(name="error",type="chain",location="editProcessNode")
	})
	public String saveProcessNode(){
		this.processNodeService.save(processNode);
		return SUCCESS;
	}
	@Action("editProcessNode")
	public String editProcessNode(){
		return SUCCESS;
	}
	@Action(value="removeProcessNode",results={
			@Result(name="success",type="redirect",location="listProcessNode"),
			@Result(name="error",type="chain",location="listProcessNode")
	})
	public String removeProcessNode(){
		if(ids == null){
			this.setPrompt("请选择要删除的数据行！");
			return ERROR;
		}
		this.processNodeService.batchRemove(ids);
		return SUCCESS;
	}
}
